using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class Member_ShopProductSale : Member, IRequiresSessionState
{
	protected DropDownList searchProductType;
	protected TextBox ProductName;
	protected DropDownList ProductType;
	protected CheckBox bid;
	protected CheckBox discount_join;
	protected DropDownList show_type;
	protected Button search;
	protected GridView GridView1;
	protected Button Stop_Button;
	protected Button Elite_Button;
	protected Button btn_editProducts;
	protected Button Button1;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			this.GridViewDataBound();
		}
	}
	protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		if (e.Row.RowType == DataControlRowType.DataRow)
		{
			e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
			e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
		}
	}
	protected void Button_Command(object sender, CommandEventArgs e)
	{
		string text = Text.CheckNumList(Fetch.GetOrPost("Product_Select"));
		Shop_Product shop_Product = new Shop_Product(this.conn);
		if (text != "")
		{
			string text2 = text;
			string[] array = text2.Split(new char[]
			{
				','
			});
			for (int i = 0; i < array.Length; i++)
			{
				if (e.CommandName.ToString() == "StopSale")
				{
					int num = this.conn.Execute("delete HL_GroupShopProduct where MainProductID =" + int.Parse(array[i]));
				}
			}
			int num2 = shop_Product.EditSaleProductProtity(text2, e.CommandName.ToString());
			this.GridViewDataBound();
		}
	}
	protected void QucikSearch_Click(object sender, EventArgs e)
	{
		this.GridViewDataBound();
	}
	protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
	{
		this.GridView1.PageIndex = e.NewPageIndex;
		this.GridViewDataBound();
	}
	protected void GridViewDataBound()
	{
		string str = base.user.UserID.ToString();
		string text = " Select ProductID,ProductName,ProductImageUrl,ProductSmallImageUrl,Stocks,Hits,BidTimes,NeedPresentExp, case when ProductType =1 then StandPrice ";
		text += " when (ProductType=3 and TeamNum=1)  then TeamPrice1 when(ProductType=3 and TeamNum=2) then TeamPrice2 when(ProductType=3 and TeamNum=3) then TeamPrice3 when(ProductType=3 and TeamNum=4) then TeamPrice4 when(ProductType=3 and TeamNum=5) then TeamPrice5 when ProductType =4 then StandPrice when ProductType =5 then StandPrice else AuctionStartPrice end as StandPrice, DATEDIFF(s,BeginDate,EndDate) as LeftTime,ProductType, CurrentPrice,BeginDate,ClassID ";
		text = text + " From HLShop_Product WHERE EnableSale=1 and Stocks>=0 and DateDiff(s,EndDate,getdate())<=0 and SalerID=" + str + " ";
		string text2 = Text.ReplaceBadChar(this.searchProductType.SelectedValue);
		string text3 = Text.ReplaceBadChar(this.ProductName.Text);
		string text4 = Text.ReplaceBadChar(this.ProductType.SelectedValue);
		bool @checked = this.bid.Checked;
		bool checked2 = this.discount_join.Checked;
		string text5 = Text.ReplaceBadChar(this.show_type.SelectedValue);
		if (@checked)
		{
			text += " and (BidTimes>0 Or BuyTimes>0)";
		}
		if (checked2)
		{
			text += " and (Discount<100 and Discount>0)";
		}
		if (text2 != "-1")
		{
			text = text + " and IsElite=" + text2;
		}
		if (text3 != "")
		{
			text = text + " and ProductName like '%" + text3 + "%'";
		}
		if (text4 != "-1")
		{
			text = text + " and ProductType='" + text4 + "'";
		}
		if (text5 != "-1")
		{
			string text6 = text5;
			switch (text6)
			{
			case "1":
				text += " Order By BeginDate Desc";
				break;
			case "2":
				text += " Order By BeginDate Asc";
				break;
			case "3":
				text += " Order By StandPrice Desc";
				break;
			case "4":
				text += " Order By StandPrice Asc";
				break;
			case "5":
				text += " Order By Hits Desc";
				break;
			case "6":
				text += " Order By Hits Asc";
				break;
			case "7":
				text += " Order By Stocks Desc";
				break;
			case "8":
				text += " Order By Stocks Asc";
				break;
			}
		}
		else
		{
			text += " order By ProductID Desc";
		}
		DataTable dataTable = this.conn.GetDataTable(text);
		this.GridView1.DataSourceID = "";
		this.GridView1.DataSource = dataTable;
		this.GridView1.DataBind();
	}
	protected void btn_editProducts_Click(object sender, EventArgs e)
	{
		string text = Text.CheckNumList(Fetch.GetOrPost("Product_Select"));
		if (text == "")
		{
			this.WriteErrMsg("", "未选中编辑项", "");
		}
		else
		{
			base.Response.Redirect("EditProducts.aspx?tag=Sale&productIDS=" + text);
		}
	}
}
